<?php
declare (strict_types = 1);

namespace app\command;

use common\service\GoodsService;
use common\service\JobService;
use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\input\Option;
use think\console\Output;
use think\facade\Db;

class orderConsole extends Command
{
    protected function configure()
    {
        // 指令配置
        $this->setName('orderconsole')
            ->setDescription('the orderconsole command');
    }

    protected function execute(Input $input, Output $output)
    {
        /*TODO:
         * 查找出过期时间大于当前时间的数据
         * 如果当前时间等于过期时间  回滚库存管理并且订单该为已取消状态
         * */
       $orderNoPay = Db::name('order')->where([
                    'status'=>0
        ])->whereTime('expire_time','>=',time())->select()->toArray();
       foreach ($orderNoPay as &$item)
       {
           if ($item['expire_time'] == time())
           {
               $data = [
                   'id' =>$orderNoPay['goods_id'],
                   'count' =>10,
                   'title' =>'油泼面_'.$orderNoPay['goods_id'],
                   'amount' =>'10.00',
               ];
               $trueFlag = GoodsService::pushSeckillStock(1,true,$data['goodInfo']);    //失败回滚库存管理
           }else
           {
               return true;
           }
       }
        // 指令输出
        $output->writeln('orderconsole');
    }
}
